package test.zdx.杂七杂八;

public class Homework
{
    public static void main(String[] args) {
        System.out.println(getTheNumOf1(3));// 11
        System.out.println(getTheNumOf1(7));// 111
        System.out.println(getTheNumOf1(15));// 1111
        System.out.println(getTheNumOf1(31));// 11111
    }

    public static  int getTheNumOf1(int num)
    {
        String string = Integer.toBinaryString(num);
        int str_len = string.length();
        char[] ch_array = string.toCharArray();
        int cnt = 0;
        for(char ch : ch_array){
            if(ch == '1')
            {
                cnt++;
            }
        }
        return cnt;
    }

    //本题水仙花数，为提高程序的鲁棒性和健壮性，本题范围为从两位数起手
    //参数列表 几位数 .
}

